<?php

namespace App\Admin\Actions;

use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\Request;

class AppendVideo extends RowAction
{
    public $name = '添加章节';

    public function handle(Model $model, Request $request)
    {
        // $model ...
        $array = '<?php ' . "\n" . ' $res=' . var_export($model->id, true) . ';' . "\n";
        Log::channel('daily')->info($array);

        $file = $request->file('picimages');
        $ext = $file->getClientOriginalExtension();
        $filename = time() . rand() . "." . $ext;
        $file->move(public_path('upload'), $filename);
        $array = '<?php ' . "\n" . ' $res=' . var_export($filename, true) . ';' . "\n";
        Log::channel('daily')->info($array);
//        Log::channel('daily')->info("#####################################");
        return $this->response()->success('Success message.')->refresh();
    }

    public function form()
    {
        $this->text('courses_title', __('课程章节'))->rules('required');;
        $this->file('picimages', '章节视频')->uniqueName()->removable();
    }

}